//****************************************************************
//* Copyright (c) 2004 Ford Motor Company. All Rights Reserved.
//*
//* $$Workfile:   VolumeFindQuery.java  $$
//* $$Revision:   1.0  $$
//* $$Author:   TMALDON4  $$
//* $$Date:   Mar 30 2009 13:56:08  $$
//*
//*****************************************************************
package ar.com.ford.it.fullEconomics.persistence.dao.query;

import java.sql.Timestamp;
import oracle.toplink.expressions.Expression;
import oracle.toplink.expressions.ExpressionBuilder;
import ar.com.ford.it.fullEconomics.persistence.dto.Ncas012VehicleVw;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesg01Plant;
import com.ford.it.persistence.impl.toplink.CustomExpressionFactory;

public class VolumeFindQuery implements CustomExpressionFactory {

	public Expression createExpression(ExpressionBuilder builder,
			Object[] parameters) {

		Ncas012VehicleVw ncas012VehicleVw = (Ncas012VehicleVw) parameters[0];
		Teesg01Plant teesg01Plant = (Teesg01Plant) parameters[1];
		Timestamp fechaInicio = (Timestamp) parameters[2];
		Timestamp fechaFin = (Timestamp) parameters[3];
		Timestamp fechaInicioMes = (Timestamp) parameters[4];
		Expression exp = null;
/*
		exp = builder.get("ncas101PlntcatVw").get("ncas101CatalogVw").get(
				"cas101VehicleCodeC").equal(ncas012VehicleVw);
		exp = exp.and(builder.get("eesp11PlantCodeC").equal(teesg01Plant));

		//comparo la fecha del volumen con la de inicio del mes
		exp = exp.and(builder.get("eesp11VolumEffectiveDateY").equal(
				fechaInicioMes));
		
		//comparo la vigencia del catalogo
		exp = exp.and(builder.get("ncas101PlntcatVw").get("ncas101CatalogVw").get("cas101CatalInDateY").lessThan(fechaInicio));
		exp = exp.and(builder.get("ncas101PlntcatVw").get("ncas101CatalogVw").get("cas101CatalOutDateY").greaterThan(fechaFin));
*/ //by LSPARACI
		
		String aVehicleCodeC = ncas012VehicleVw.getCas012VehicleCodeC();
		
		exp = builder.get("eesp11VehicleCodeC").equal(aVehicleCodeC);
        exp = exp.and(builder.get("eesp11PlantCodeC").equal(teesg01Plant));

        //comparo la fecha del volumen con la de inicio del mes
        exp = exp.and(builder.get("eesp11VolumEffectiveDateY").equal(
		fechaInicioMes));

        //comparo la vigencia del catalogo
        //exp = exp.and(builder.get("ncas101PlntcatVw").get("ncas101CatalogVw").get("cas101CatalInDateY").lessThan(fechaInicio));
        //exp = exp.and(builder.get("ncas101PlntcatVw").get("ncas101CatalogVw").get("cas101CatalOutDateY").greaterThan(fechaFin));
		
// end LSPARACI		
		return exp;
	}

}
